<template>
  <div>
    <CloseHeader title="申请列表" :show-slot="multiSelection.length > 0">
      <div class="batch">
        <el-button size="small" type="success" @click="batchConfirm">批量同意</el-button>
        <el-button size="small" @click="batchDeny">批量拒绝</el-button>
      </div>
    </CloseHeader>
    <el-table
        :data="requestList"
        style="width: 100%"
        :row-style="{cursor:'pointer'}"
        @row-click="rowClick"
        @selection-change="handleSelectionChange"
    >
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="name"
          align="center"
          label="申请人姓名">
      </el-table-column>
      <el-table-column
          prop="mobile"
          align="center"
          label="手机">
      </el-table-column>
      <el-table-column
          prop="email"
          align="center"
          label="邮箱">
      </el-table-column>
      <el-table-column
          prop="comment"
          align="center"
          label="备注">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import CloseHeader from '@/components/common/close-header'
import {findJoinRequestList, joinDenyBatch, joinConfirmBatch, findPeopleList} from "@/api/auth/tenant";

export default {
  name: "people-invitation-list",
  components: {
    CloseHeader
  },
  data() {
    return {
      multiSelection: [],
      requestList: []
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      findJoinRequestList().then(res => {
        if(res.code == 200) {
          this.requestList = res.data
        }
      })
    },
    batchConfirm() {
      console.log(this.getJoinIds())
      joinConfirmBatch(this.getJoinIds()).then(res => {
        if(res.code == 200) {
          this.$message.success('操作成功，'+ this.multiSelection.length + '名新成员加入企业！')
          this.multiSelection = []
          this.loadData()
        }
      })
    },
    batchDeny() {
      joinDenyBatch(this.getJoinIds()).then(res => {
        if(res.code == 200) {
          this.$message.success('拒绝操作成功')
          this.multiSelection = []
          this.loadData()
        }
      })
    },
    batchDelete() {

    },
    getJoinIds() {
      let arr = []
      this.multiSelection.forEach(function (item) {
        arr.push(item.userId)
      })
      return arr
    },
    rowClick() {

    },
    handleSelectionChange(val) {
      this.multiSelection = val
    }
  }
}
</script>

<style scoped lang="less">
/deep/.batch {
  padding: 0 15px;
}
</style>
